package com.wangyi.im.remoting;

import com.alibaba.fastjson.JSONObject;
import com.wangyi.im.execute.IMEventSubscribeExecute;
import com.wangyi.im.execute.IMFriendExecute;
import com.wangyi.im.request.IMEventSubscribeAddRequest;
import com.wangyi.im.request.IMEventSubscribeGetRequest;
import com.wangyi.im.request.IMFriendAddRequest;
import com.wangyi.im.request.IMFriendGetRequest;
import com.wangyi.im.response.IMEventSubscribeGetResponse;
import com.wangyi.im.response.IMFriendGetResponse;
import com.wangyi.im.response.IMResponse;
import com.wangyi.im.utils.BuildDataUtil;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.util.List;

import static com.wangyi.im.constants.CommonConstants.FRIENDS;
import static com.wangyi.im.constants.CommonConstants.SUBSCRIBES;

public class IMEventSubscribeRemoting extends Remoting {

    public IMEventSubscribeRemoting(String baseUrl, String appKey, String appSecret) {
        super(baseUrl, appKey, appSecret);
    }

    public IMResponse<Boolean> addSubscribe(IMEventSubscribeAddRequest imEventSubscribeAddRequest){
        Call<JSONObject> call = getRetrofit(imEventSubscribeAddRequest).create(IMEventSubscribeExecute.class).addSubscribe();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildData(retrofitResponse, Boolean.class, null);
    }

    public IMResponse<List<IMEventSubscribeGetResponse>> getSubscribe(IMEventSubscribeGetRequest imEventSubscribeGetRequest){
        Call<JSONObject> call = getRetrofit(imEventSubscribeGetRequest).create(IMEventSubscribeExecute.class).getSubscribe();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildListData(retrofitResponse, IMEventSubscribeGetResponse.class, SUBSCRIBES);
    }
}
